<?php

use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use yii\helpers\ArrayHelper;
use backend\models\UserDepartment;
use backend\models\UserPost;
use daimakuai\avatar\AvatarWidget;
use daimakuai\avatar\AvatarViewWidget;
use daimakuai\avatar\AvatarUploadWidget;

/* @var $this yii\web\View */
/* @var $model backend\models\User */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="user-form">

    <?php $form = ActiveForm::begin([
        'id'=>'user',
        'layout'=>'horizontal',
        'validateOnBlur' => false,
    ]); ?>

    <?= $form->field($model, 'avatar')->widget(AvatarViewWidget::className()) ?>

    <?= $form->field($model, 'username')->textInput(['maxlength' => true]) ?>

    <?php if ( $model->isNewRecord ): ?>

        <?= $form->field($model, 'password')->passwordInput(['maxlength' => 255, 'autocomplete'=>'off']) ?>

        <?= $form->field($model, 'repeat_password')->passwordInput(['maxlength' => 255, 'autocomplete'=>'off']) ?>
    <?php endif; ?>

    <?= $form->field($model, 'realname')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'department')
        ->dropDownList(ArrayHelper::map(UserDepartment::find()->asArray()->all(), 'name', 'description'), ['prompt'=>'']) ?>

    <?= $form->field($model, 'post')
        ->dropDownList(ArrayHelper::map(UserPost::find()->asArray()->all(), 'name', 'description'), ['prompt'=>'']) ?>

    <?= $form->field($model, 'is_leader')->checkbox() ?>


    <div class="form-group">
        <div class="col-sm-offset-3 col-sm-9">
            <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
        </div>
    </div>

    <?php ActiveForm::end(); ?>

    <div class="form-group">
        <div class="col-sm-offset-3 col-sm-9">
            <div style="width:100px;">
                <?php $b = new AvatarUploadWidget(['imageUrl'=>'/image/common/hearder-user.png']);echo $b->setFooter(); ?>
            </div>
        </div>
    </div>

</div>

